//
//  LSNavViewController.swift
//  LSWeibo1
//
//  Created by 李明禄 on 2018/11/28.
//  Copyright © 2018 SocererGroup. All rights reserved.
//

import UIKit

class LSNavViewController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        navigationBar.isHidden = true
    }
 
//    重写父类的pushViewController
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        if children.count > 0 {
            
            viewController.hidesBottomBarWhenPushed = true
            
            if let vc = (viewController as? BaseViewController) {
                
                var title = "返回"
                if children.count == 1 {
                    
                    title = children.first?.title ?? "返回"
                }
                
                vc.navBarItem.leftBarButtonItem = UIBarButtonItem.init(
                    title: title,
                    normalColor: .darkGray,
                    highlightedColor: .orange,
                    isBack: true,
                    target: self,
                    action: #selector(clickReturn)
                )
            }
            
        }
        
        super.pushViewController(viewController, animated: animated)
    }
    

}

extension UINavigationController {
    @objc func clickReturn() {
        
       popViewController(animated: true)
    }
    
}
